package com.saya.model;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.saya.utils.Utils;

public class UserLogin {
	private String phoneNumber;
	  private String deviceId;
	  private String loginDate;
	  private String token;

	  public String getPhoneNumber()
	  {
	    return this.phoneNumber;
	  }
	  public void setPhoneNumber(String phoneNumber) {
	    this.phoneNumber = phoneNumber;
	  }
	  public String getDeviceId() {
	    return this.deviceId;
	  }
	  public void setDeviceId(String deviceId) {
	    this.deviceId = deviceId;
	  }
	  public String getDate() {
	    return this.loginDate;
	  }
	  public void setDate(String logindate) {
	    this.loginDate = logindate;
	  }
	  public String getToken() {
	    return this.token;
	  }
	  public void setToken(String token) {
	    this.token = token;
	  }

	  public UserLogin()
	  {
	  }

	  public UserLogin(String phoneNumber, String deviceId) {
	    this.phoneNumber = phoneNumber;
	    this.deviceId = deviceId;
	  }

	  public String CreateorUpdate(UserLogin userLogin) {
	    Entity user = Utils.getEntity("User", userLogin.getPhoneNumber());
	    Entity e = new Entity("UserLogin", user.getKey());
	    e.setProperty("PhoneNumber", userLogin.getPhoneNumber());
	    e.setProperty("DeviceId", userLogin.getDeviceId());
	    e.setProperty("LoginDate", Utils.getCurrentDate());
	    Key k = Utils.persistEntity(e);
	    if (k != null) {
	      return KeyFactory.keyToString(k);
	    }
	    return null;
	  }
}
